/******************************************************************************
 Copyright (c) 2020-2025 Qualcomm Technologies International, Ltd.
 All Rights Reserved.
 Qualcomm Technologies International, Ltd. Confidential and Proprietary.

******************************************************************************/

#include "csr_synergy.h"

#include "csr_bt_cm_main.h"
#include "csr_bt_cm_dm.h"
#include "csr_log_text_2.h"
#include "csr_bt_cm_le.h"
#include "csr_random.h"

#ifdef CSR_BT_INSTALL_EXTENDED_ADVERTISING

void CsrBtCmDmExtAdvRegisterAppAdvSetCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_REGISTER_APP_ADV_SET_CFM_T *dmPrim = msg;
    CmExtAdvRegisterAppAdvSetCfm *prim;

    if(dmPrim->status == HCI_SUCCESS)
    {
        cmData->extAdvAppHandle[dmPrim->adv_handle] = cmData->dmVar.appHandle;
    }

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_REGISTER_APP_ADV_SET_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->advHandle = dmPrim->adv_handle;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));	
    CsrBtCmDmLocalQueueHandler();
}

void CsrBtCmDmExtAdvUnregisterAppAdvSetCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_UNREGISTER_APP_ADV_SET_CFM_T *dmPrim = msg;
    CmExtAdvUnregisterAppAdvSetCfm *prim;

    if((dmPrim->status == HCI_SUCCESS) &&
       (cmData->advHandle < MAX_EXT_ADV_APP))
    {
        cmData->extAdvAppHandle[cmData->advHandle] = CSR_SCHED_QID_INVALID;
    }

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_UNREGISTER_APP_ADV_SET_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->advHandle = cmData->advHandle;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
static void CmDmExtSetParamsRPAGenPerAdvSetCfm(cmInstanceData_t *cmData, CsrBtCmPrim prim_type)
{
/* If advHandle is valid, all paraments for the selected advertisement set are initialised */
    if (cmData->advHandle < MAX_EXT_ADV_APP)
    {
        /*Bit 0 is set for enabling RPA generation per advertisement set feature */
        if ((cmData->extAdvSet[cmData->advHandle].extAdvFeatureMask & CM_RPA_GEN_PER_ADV_SET_MASK) == CM_RPA_GEN_PER_ADV_SET_MASK)
        {
            cmData->extAdvSet[cmData->advHandle].timeout = CsrRandom(CsrRandomSeed()) % 
                                                      (CM_LE_ADV_SET_RPA_CHANGE_TIMER_MAX - CM_LE_ADV_SET_RPA_CHANGE_TIMER_MIN + 1) + 
                                                       CM_LE_ADV_SET_RPA_CHANGE_TIMER_MIN;
            cmData->extAdvSet[cmData->advHandle].abort = FALSE;

            /* If any internal disable advertisement procedure from CM is not running while initiating set params request, state is updated as none.*/
            if (cmData->extAdvSet[cmData->advHandle].state != CM_RPA_STATE_EXT_ADV_DISABLE)
            {
                cmData->extAdvSet[cmData->advHandle].state = CM_RPA_STATE_NONE;
            }
        }
    }
    else
    {
        CsrGeneralException(CsrBtCmLto,
                            0,
                            CSR_BT_CM_PRIM,
                            prim_type,
                            0,
                            "CmDmExtSetParamsRPAGenPerAdvSetCfm invalid adv handle sent from cfm handler\n");
    }
    CSR_UNUSED(prim_type);
}
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */

void CsrBtCmDmExtAdvSetParamsCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_SET_PARAMS_CFM_T *dmPrim = msg;
    CmExtAdvSetParamsCfm *prim;

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
    /* If feature mask for RPA gen per adv set feature is enabled then CmDmExtSetParamsRPAGenPerAdvSetCfm will peroform the required handling */
    CmDmExtSetParamsRPAGenPerAdvSetCfm(cmData, CSR_BT_CM_EXT_ADV_SET_PARAMS_CFM);
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_SET_PARAMS_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->advSid = dmPrim->adv_sid;
    prim->advHandle = cmData->advHandle;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

void CsrBtCmDmExtAdvSetDataCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_HCI_ULP_EXT_ADV_SET_DATA_CFM_T *dmPrim = msg;
    CmExtAdvSetDataCfm *prim;

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_SET_DATA_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->advHandle = cmData->advHandle;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

void CsrBtCmDmExtAdvSetScanRespDataCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_HCI_ULP_EXT_ADV_SET_SCAN_RESP_DATA_CFM_T *dmPrim = msg;
    CmExtAdvSetScanRespDataCfm *prim;

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_SET_SCAN_RESP_DATA_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->advHandle = cmData->advHandle;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

void CsrBtCmDmExtAdvEnableCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_ENABLE_CFM_T *dmPrim = msg;

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
    /*Bit 0 is set for enabling RPA generation per advertisement set feature.*/
    /* Extended Advertisement is in the process of initiation and it has been initiated by CM */
    if (cmData->advHandle < MAX_EXT_ADV_APP &&
       ((cmData->extAdvSet[cmData->advHandle].extAdvFeatureMask & CM_RPA_GEN_PER_ADV_SET_MASK) == CM_RPA_GEN_PER_ADV_SET_MASK) &&
        cmData->extAdvSet[cmData->advHandle].state != CM_RPA_STATE_NONE &&
        cmData->dmVar.appHandle == CSR_BT_CM_IFACEQUEUE)
    {
        /* CM has request to enable ext adv or disable ext adv in case of duration expiry for multi enable adv set. 
           One iteration of advertisement enable has ended and DM queue is unlocked 
           Please note that in case of Extended advertisement disable request initiated by CM, DM queue is not unlocked 
           */
        if (cmData->extAdvSet[cmData->advHandle].state == CM_RPA_STATE_EXT_ADV_ENABLE ||
           cmData->extAdvSet[cmData->advHandle].state == CM_RPA_STATE_EXT_ADV_MULTI_DISABLE)
        {
            cmData->extAdvSet[cmData->advHandle].state = CM_RPA_STATE_NONE;
            CsrBtCmDmLocalQueueHandler();
        }
        /* Ext adv enable/disable request has failed so the process is aborted..*/
        if (dmPrim->status != HCI_SUCCESS)
        {
            CSR_LOG_TEXT_ERROR((CsrBtCmLto, 0, "Enable/Disable for single or multi adv has failed for the adv set 0x%x.", cmData->advHandle));
            CmDmExtAdvEnableReqInitiateAbort(cmData, cmData->advHandle);
        }

    }
    /*Extended Advertisement was enabled/disabled by application.*/
    else
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */
    {

        CmExtAdvEnableCfm *prim;

        prim = CsrPmemAlloc(sizeof(*prim));
        prim->type = CSR_BT_CM_EXT_ADV_ENABLE_CFM;
        prim->resultCode = (CsrBtResultCode) dmPrim->status;
        prim->advHandle = cmData->advHandle;

        CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
        CsrBtCmDmLocalQueueHandler();
    }
}

void CsrBtCmDmExtAdvReadMaxAdvDataLenCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_READ_MAX_ADV_DATA_LEN_CFM_T *dmPrim = msg;
    CmExtAdvReadMaxAdvDataLenCfm *prim;

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_READ_MAX_ADV_DATA_LEN_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->maxAdvData = dmPrim->max_adv_data;
    prim->maxScanRespData = dmPrim->max_scan_resp_data;
    prim->advHandle = cmData->advHandle;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

void CsrBtCmDmExtAdvTerminatedIndHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_TERMINATED_IND_T *dmPrim = msg;
    CmExtAdvTerminatedInd *prim;

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_TERMINATED_IND;
    prim->advHandle = dmPrim->adv_handle;
    prim->reason = dmPrim->reason;
    CsrBtAddrCopy(&(prim->addrt), &(dmPrim->addrt));
    prim->eaEvents = dmPrim->ea_events;
    prim->maxAdvSets = dmPrim->max_adv_sets;
    prim->advBits = dmPrim->adv_bits;

    if(dmPrim->adv_handle < MAX_EXT_ADV_APP)
    {
        CSR_LOG_TEXT_WARNING((CsrBtCmLto, 0, "CsrBtCmDmExtAdvTerminatedIndHandler id:%d",
                                cmData->extAdvAppHandle[dmPrim->adv_handle]));
        if(cmData->extAdvAppHandle[dmPrim->adv_handle] != CSR_SCHED_QID_INVALID)
        {
#ifdef INSTALL_RPA_GEN_PER_ADV_SET
            /* Bit 0 is set for enabling RPA generation per advertisement set feature.
               Advertisement set has stopped advertising due to connection establishement on it.
               Any ongoing extended advertisement process on this adv set for this feature is be aborted.*/
            if (prim->advHandle < MAX_EXT_ADV_APP &&
                (cmData->extAdvSet[prim->advHandle].extAdvFeatureMask & CM_RPA_GEN_PER_ADV_SET_MASK) == CM_RPA_GEN_PER_ADV_SET_MASK &&
                prim->reason == CM_EXT_ADV_TERMINATED_CONN)
            {
                CmDmExtAdvEnableReqInitiateAbort(cmData, prim->advHandle);
            }
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */

            CsrSchedMessagePut(cmData->extAdvAppHandle[dmPrim->adv_handle], CSR_BT_CM_PRIM, (prim));

            /* Clear the App handle for legacy adverts.
             * For extended adverts, the APP handle gets cleared on Unregister call success. But since
             * there is no unregister call for legacy adverts, we will need to clear the APP handle here.
             */
            if(dmPrim->adv_handle == ADV_HANDLE_FOR_LEGACY_API)
            {
                cmData->extAdvAppHandle[dmPrim->adv_handle] = CSR_SCHED_QID_INVALID;
            }
        }
    }
}

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
static void cmDmExtAdvParamsAssignTimerSet(cmInstanceData_t *cmData)
{
    CsrUint32 extAdvDelayus;
    DM_ULP_EXT_ADV_SET_RANDOM_ADDR_CFM_T *dmPrim = (DM_ULP_EXT_ADV_SET_RANDOM_ADDR_CFM_T *)cmData->recvMsgP;
    CsrBtAddrCopy(&(cmData->extAdvSet[dmPrim->adv_handle].random_addr), &(dmPrim->random_addr));
    CsrSchedTimerCancel(cmData->extAdvSet[dmPrim->adv_handle].timerId, NULL, NULL);

    extAdvDelayus = cmData->extAdvSet[dmPrim->adv_handle].timeout * CSR_SCHED_MILLISECOND;

    /*If the set random address request was iniatited by CM in case of multi adv enable, then confirmation will be not be sent to application.*/
    if (cmData->dmVar.lockMsg != CSR_BT_CM_EXT_ADV_MULTI_ENABLE_REQ)
    {
        cmData->extAdvSet[dmPrim->adv_handle].state = (cmData->dmVar.appHandle == CSR_BT_CM_IFACEQUEUE) ?
                                                       CM_RPA_STATE_EXT_ADV_ENABLE : CM_RPA_STATE_NONE;
    }

    else
    {
        cmData->extAdvSet[dmPrim->adv_handle].state = CM_RPA_STATE_NONE;
    }
    /* Timer is started.*/
    CSR_LOG_TEXT_INFO((CsrBtCmLto, 0, "Timer has started for adv set: 0x%x", dmPrim->adv_handle));
    cmData->extAdvSet[dmPrim->adv_handle].timerId =
    CsrSchedTimerSet(extAdvDelayus,
                     CmDmExtAdvEnableReqTimeout,
                     (CsrUint16)dmPrim->adv_handle,
                     (void * ) cmData);
}

/* This function determines if DM queue has to be unlocked or not for single adv and multi adv scenarios.*/
static CsrBool cmDmExtAdvSetRandomAddrAdvHandling(cmInstanceData_t *cmData, CsrUint8 adv_handle, CsrBool success)
{
    if (cmData->dmVar.lockMsg == CSR_BT_CM_EXT_ADV_ENABLE_REQ)
    {
        /* If adv enable req from app has failed then we'll not unlock the queue.*/
        if(success == TRUE || cmData->dmVar.appHandle != CSR_BT_CM_IFACEQUEUE)
        {
            dm_ext_adv_enable_req(adv_handle, 0x01, NULL);
            return TRUE;
        }
    }

    else if (cmData->dmVar.lockMsg == CSR_BT_CM_EXT_ADV_MULTI_ENABLE_REQ)
    {
        if (success == FALSE || CmDmExtAdvMultiEnableSetRandomAddr(cmData))
        {
            CmExtAdvMultiEnableReq *multiExtadvEnablePrim = (CmExtAdvMultiEnableReq *)cmData->dmVar.context;
            /* The procedure for setting RPA is completed, appHandle has been reset to original value.*/
            cmData->dmVar.appHandle = multiExtadvEnablePrim->appHandle;

            dm_ext_adv_multi_enable_req(multiExtadvEnablePrim->enable,
                                        multiExtadvEnablePrim->numSets,
                                        (EA_ENABLE_CONFIG_T *) multiExtadvEnablePrim->config,
                                        NULL);
            return TRUE;
        }
    }
    return FALSE;
}
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */

void CsrBtCmDmExtAdvSetRandomAddrCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_SET_RANDOM_ADDR_CFM_T *dmPrim = msg;

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
    /* Bit 0 is set for enabling RPA generation per advertisement set feature.
       Extended Advertisement is in the process of initiation 
       and set random address request has not been initiated by application */
    if (dmPrim->adv_handle < MAX_EXT_ADV_APP &&
      ((cmData->extAdvSet[dmPrim->adv_handle].extAdvFeatureMask & CM_RPA_GEN_PER_ADV_SET_MASK) == CM_RPA_GEN_PER_ADV_SET_MASK) &&
        cmData->extAdvSet[dmPrim->adv_handle].state != CM_RPA_STATE_NONE &&
        cmData->dmVar.lockMsg != CSR_BT_CM_EXT_ADV_SET_RANDOM_ADDR_REQ)
    {
        /* Set RPA request has failed so the process needs to be aborted and confirmation message is sent to app.*/
        if (dmPrim->status != 0x00)
        {
            CSR_LOG_TEXT_INFO((CsrBtCmLto, 0, "Aborting the ext adv with RPA generation process due to failure of set random addr request."));
            CmDmExtAdvEnableReqInitiateAbort(cmData, dmPrim->adv_handle);
            /* In multi-enable case , DM queue is not unlocked, while for single adv enable case, it is unlocked*/
            if (!cmDmExtAdvSetRandomAddrAdvHandling(cmData, dmPrim->adv_handle, FALSE))
            {
                CsrBtCmDmLocalQueueHandler();
            }
        }

        else
        {
            switch (cmData->extAdvSet[dmPrim->adv_handle].state)
            {
                /* Set address request is initiated by CM.*/
                case CM_RPA_STATE_SET_ADDR:
                {
                    /* Connection is not initiated on this adv set till now */
                    if (cmData->extAdvSet[dmPrim->adv_handle].abort == FALSE)
                    {
                        cmDmExtAdvParamsAssignTimerSet(cmData);
                        /* Single adv/ multi adv enable request is sent to DM.*/
                        (void) cmDmExtAdvSetRandomAddrAdvHandling(cmData, dmPrim->adv_handle, TRUE);
                    }
                    /* Connection is initiated on this adv set 
                       Advertisement set parameters are cleared and DM queue is unlocked.*/
                    else
                    {
                        CmDmExtAdvEnableReqCleanup(cmData, dmPrim->adv_handle);
                        /* DM queue is unlocked in this case.*/
                        if (!cmDmExtAdvSetRandomAddrAdvHandling(cmData, dmPrim->adv_handle, FALSE))
                        {
                            CsrBtCmDmLocalQueueHandler();
                        }
                    }
                    break;
                }

                default:
                {
                    CSR_LOG_TEXT_INFO((CsrBtCmLto, 0, "Aborting the ext adv with RPA generation process due to invalid state found during set random addr cfm."));
                    CmDmExtAdvEnableReqInitiateAbort(cmData, dmPrim->adv_handle);
                    /* In multi-enable adv scenario, DM queue is not unlocked, while for single adv scenario, it is unlocked.*/
                    if (!cmDmExtAdvSetRandomAddrAdvHandling(cmData, dmPrim->adv_handle, FALSE))
                    {
                        CsrBtCmDmLocalQueueHandler();
                    }

                    break;
                }
            }
        }
    }
    /* Set random request was initiated by application.*/
    else
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */
    {
        CmExtAdvSetRandomAddrCfm *prim;

        prim = CsrPmemAlloc(sizeof(*prim));
        prim->type = CSR_BT_CM_EXT_ADV_SET_RANDOM_ADDR_CFM;
        prim->resultCode = (CsrBtResultCode) dmPrim->status;
        prim->advHandle = dmPrim->adv_handle;
        CsrBtAddrCopy(&(prim->randomAddr), &(dmPrim->random_addr));
        CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
        CsrBtCmDmLocalQueueHandler();
    }
}

void CsrBtCmDmExtAdvSetsInfoCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_SETS_INFO_CFM_T *dmPrim = msg;
    CmExtAdvSetsInfoCfm *prim;

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_SETS_INFO_CFM;
    prim->flags = dmPrim->flags;
    prim->numAdvSets = dmPrim->num_adv_sets;
    SynMemCpyS(prim->advSets, sizeof(CmExtAdvSetInfo) * CM_EXT_ADV_MAX_REPORTED_ADV_SETS, 
               dmPrim->adv_sets, sizeof(CmExtAdvSetInfo) * CM_EXT_ADV_MAX_REPORTED_ADV_SETS);

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

void CsrBtCmDmExtAdvMultiEnableCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_MULTI_ENABLE_CFM_T *dmPrim = msg;
    CmExtAdvMultiEnableCfm *prim;

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
    CmExtAdvMultiEnableReq *multiExtadvEnablePrim;
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CSR_BT_CM_EXT_ADV_MULTI_ENABLE_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->maxAdvSets = dmPrim->max_adv_sets;
    prim->advBits = dmPrim->adv_bits;

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
    multiExtadvEnablePrim = (CmExtAdvMultiEnableReq *)cmData->dmVar.context;

    if(multiExtadvEnablePrim != NULL)
    {
    /* Multi adv disable has failed and abort is initiated for the set which have RPA generation per adv set feature enabled.*/
        if (dmPrim->status != HCI_SUCCESS)
        {
            CsrUint8 i;
            for (i = 0; i < multiExtadvEnablePrim->numSets; i++)
            {
                if (cmData->extAdvSet[multiExtadvEnablePrim->config[i].advHandle].isMultiEnable)
                {
                    CmDmExtAdvEnableReqInitiateAbort(cmData, multiExtadvEnablePrim->config[i].advHandle);
                }
            }
        }
    }

    /* Ext adv context freed on receiving confirmation.*/
    CsrPmemFree(cmData->dmVar.context);
    cmData->dmVar.context = NULL;
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

#ifdef INSTALL_CM_EXT_ADV_SET_PARAM_V2
void CmDmExtAdvSetParamsV2CfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_SET_PARAMS_V2_CFM_T *dmPrim = msg;
    CmDmExtAdvSetParamsV2Cfm *prim;

#ifdef INSTALL_RPA_GEN_PER_ADV_SET
    /* If feature mask for RPA gen per adv set feature is enabled then CmDmExtSetParamsRPAGenPerAdvSetCfm will peroform the required handling */
    CmDmExtSetParamsRPAGenPerAdvSetCfm(cmData, CM_DM_EXT_ADV_SET_PARAMS_V2_CFM);
#endif /* INSTALL_RPA_GEN_PER_ADV_SET */

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CM_DM_EXT_ADV_SET_PARAMS_V2_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->advSid = dmPrim->adv_sid;
    prim->advHandle = cmData->advHandle;
    prim->selectedTxPower = dmPrim->selected_tx_pwr;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}
#endif

void CmDmExtAdvGetAddressCfmHandler(cmInstanceData_t *cmData, void *msg)
{
    DM_ULP_EXT_ADV_GET_ADDR_CFM_T *dmPrim = msg;
    CmDmExtAdvGetAddrCfm *prim;

    prim = CsrPmemAlloc(sizeof(*prim));
    prim->type = CM_DM_EXT_ADV_GET_ADDR_CFM;
    prim->resultCode = (CsrBtResultCode) dmPrim->status;
    prim->advHandle = dmPrim->adv_handle;
    prim->ownAddr = dmPrim->addrt;

    CsrSchedMessagePut(cmData->dmVar.appHandle, CSR_BT_CM_PRIM, (prim));
    CsrBtCmDmLocalQueueHandler();
}

#endif /* End of CSR_BT_INSTALL_EXTENDED_ADVERTISING */
